<template>
	<page-meta :root-font-size="`${fontSize}px`"></page-meta>
	<view>

		<homeNavBar ref='homeNavBar' @projChange="onNavChange" />
		<view class="main">
			<homeSwiper ref="homeSwiper" />
			<homeNavigator ref='homeNavigator' />
			<!-- <shopActivity /> -->
			<!-- <homeActivity></homeActivity> -->
			<homeCenterSwiper></homeCenterSwiper>
			<homeYijianjienan></homeYijianjienan>
			<announcement ref="announcement" />
			<!-- <homeMessage></homeMessage> -->
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex'
import homeNavBar from './home-nav-bar.vue'
import homeSwiper from './home-swiper.vue'
import homeNavigator from './home-navigator.vue'
import shopActivity from './shop-activity.vue'
import announcement from './announcement.vue'
import homeNotice from './home-notice.vue'
import homeActivity from './home-activity.vue'
import homeCenterSwiper from './home-center-swiper.vue'
import homeYijianjienan from './home-yijianjienan.vue'
import homeMessage from './home-message.vue'
export default {
	components: {
		homeNavBar,
		homeSwiper,
		homeNavigator,
		shopActivity,
		announcement,
		homeNotice,
		homeActivity,
		homeCenterSwiper,
		homeYijianjienan,
		homeMessage
	},
	computed: {
		...mapState(['fontSize'])
	},
	data() {
		return {
			userInfo: null,
			list: [{
				label: '垃圾',
				value: '10'
			},
			{
				label: '工单',
				value: '20'
			},
			{
				label: '停车',
				value: '30'
			},
			{
				label: '网格',
				value: '40'
			},
			]
		};
	},
	created() {
		if (wx.canIUse('getUpdateManager')) {
			const updateManager = wx.getUpdateManager()
			updateManager.onCheckForUpdate(function (res) {
				console.log('onCheckForUpdate', res)
				if (res.hasUpdate) {
					updateManager.onUpdateReady(function () {
						wx.showModal({
							title: '更新提示',
							content: '新版本已经准备好，是否重启应用？',
							success: function (res) {
								if (res.confirm) {
									updateManager.applyUpdate()
								}
							}
						})
					})
					updateManager.onUpdateFailed(function () {
						wx.showModal({
							title: '已经有新版本了哟~',
							content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
						})
					})
				}
			})
		} else {
			wx.showModal({
				title: '提示',
				content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
			})
		}
	},
	onLoad(options) {
		console.log(options)
		if (!uni.getStorageSync('userInfo')) {
			uni.showModal({
				title: '提示',
				content: '您还没有登录,请登录后使用',
				success: function (res) {
					if (res.confirm) {
						uni.navigateTo({
							url: '../login/login'
						})
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
		}
	},
	onShow() {
		this.userInfo = uni.getStorageSync("userInfo")
		this.$refs.homeNavBar.refresh()
		if (uni.getStorageSync('Sessionkey')) {
			this.getUserInfo()
			this.$refs.announcement.getNotice()
		}
		// this.getUserInfo()
	},
	methods: {
		onNavChange() {
			console.log(123)
			this.$refs.homeSwiper.resetProj()
		},
		getUserInfo() {
			this.$http.post('common/user/info', {
				projId: uni.getStorageSync('projId'),
				groupId: this.$config.groupId
			}).then(res => {
				// console.log(res, '用户信息111')
				if (res.code === 10000 || res.code === 50014 || res.code === 50015) {
					// this.setUserInfo(res.data)
					uni.setStorageSync('userInfo', res.data)

					uni.setStorageSync('checkStatus', res.data.checkStatus)
					if (!uni.getStorageSync('projId')) {
						uni.setStorageSync('projId', res.data.projId)
					}
				}
			})
		},
	}
}
</script>

<style lang="scss" scoped></style>
